package com.carryking.smart.rpc.spring;

import com.carryking.smart.rpc.utils.ClientBeanProxyUtils;
import org.springframework.beans.factory.FactoryBean;

/**
 * Created by jincarry on 2018/1/11.
 */
public class ClientFactoryBean<T> implements FactoryBean<T> {

    /**
     * 远程服务
     */
    private Class<T>  serviceInterface;

    /**
     * 是否异步
     */
    private boolean async = false;

    /**
     * 服务超时 单位：毫秒
     */
    private int timeOut = 5000;

    public void setServiceInterface(Class<T> serviceInterface) {
        this.serviceInterface = serviceInterface;
    }

    public T getObject() throws Exception {
        return ClientBeanProxyUtils.newInstance(serviceInterface,timeOut);
    }

    public Class<?> getObjectType() {
        return serviceInterface;
    }

    public boolean isSingleton() {
        return true;
    }
}
